﻿<!DOCTYPE html>
<html>
<head>
    <title></title>
    <link href="/style/rightdirectory.css" rel="stylesheet" />
    <script src="/script/config.js"></script>
</head>

<body>
    <h5>供货商后台菜单</h5>
    <div class="form-body">
        <div class="form-horizontal  hide" id="form">

        </div>
    </div>
</body>
</html>
<script type="text/html" id="tp-form">
    <div class="form-group">
        <label class="col-sm-2">菜单名称</label>
        <div class="col-md-6 col-sm-10">
            <input type="text" class="form-control" data-form="MenuName" placeholder="菜单名称" value="{{MenuName}}">
        </div>
    </div>

    <div class="form-group">
        <label class="col-sm-2">菜单链接</label>
        <div class="col-md-6 col-sm-10">
            <input type="text" class="form-control" data-form="Url" placeholder="菜单链接" value="{{Url}}">
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-2">菜单排序号</label>
        <div class="col-md-6 col-sm-10">
            <input type="text" class="form-control" data-form="SortId" placeholder="菜单排序号" value="{{SortId}}">
        </div>
    </div>
    {{if pageid<1}}
    <div class="form-group">
        <label class="col-sm-2">父id</label>
        <div class="col-md-6 col-sm-10">
            <input type="text" class="form-control" data-form="PId" placeholder="父id" value="{{PId}}">
        </div>
    </div>
    {{/if}}
    <div class="form-group" id="btn-img">
        <label class="col-sm-2">图标</label>
        <div class="col-md-1 col-sm-1">
            {{if pageid>0}}
            <img id="img-src" class="col-md-1 col-sm-3" data-form="Icon" src="{{Icon}}" style="width:60px;height:40px;margin-bottom:10px;" />
            {{else}}
            <img id="img-src" class="col-md-1 col-sm-3" src="/img/logo.png" style="width:60px;height:40px;margin-bottom:10px;" />
            {{/if}}
            <input type="hidden" id="Icon" data-form="Icon" value="{{Icon}}" />
            <button class="btn btn-success y-btn" type="button" id="imgUpload" onclick="btnimg()">添加</button>
        </div>
    </div>

    <div class="form-group">
        <div class="col-sm-offset-2 col-sm-10">
            <button type="button" id="btn-submit" class="btn btn-primary">保存</button>
            <button type="button" class="btn" onclick="window.history.go(-1)">退出</button>
        </div>
    </div>
</script>
<link href="/script/valid/css/tr.css" rel="stylesheet" /><!--判断如：PlatformName格式-->
<script src="/script/valid/form-valid.js?v=2018"></script>
<script src="/script/plugins/upload/js/config.js"></script>
<script>
    function btnimg() {
       //图标上传
            $.WebUploader({
                uploader: { //图片上传配置
                    fileNumLimit: 1, // 验证文件总数量, 超出则不允许加入队列
                    fileSingleSizeLimit: 40000, //验证单个文件大小是否超出限制,单位计算/b
                    accept: { //现在被上传文件 不可分体的列表
                        title: 'Images',
                        extensions: 'gif,jpg,jpeg,bmp,png,ico',
                        mimeTypes: 'image/*'
                    },
                    succee: function (rs) {
                       
                        $("#Icon").val(rs.Url);
                        $("#img-src").attr("src", rs.Url);
                        $.msgSucceed("上传成功！")
                    }
                }
            });
    }

    $(function () {
        var id = QueryPageUrlString("v");//判断是否是编辑进来的
        var formValidEvent;
        var formValidInit = function () {
            var formValidData = [
                {
                    key: "MenuName",
                    datatype: "*",
                    nullmsg: "不能为空哦",
                    errormsg: "不能为空哦"
                },
                {
                    key: "Url",
                    datatype: "*",
                    nullmsg: "不能为空哦",
                    errormsg: "不能为空哦"
                },
                {
                    key: "SortId",
                    datatype: "n",
                    nullmsg: "不能为空哦",
                    errormsg: "请正确输入！"
                },
                {
                    key: "PId",
                    datatype: "n",
                    nullmsg: "不能为空哦",
                    errormsg: "请正确输入！"
                },
            ];
            formValidEvent = $(".form-body").formValid(formValidData);
        }
        var inintData = {
            MenuName: "",
            Url: "",
            PId: "",
            SortId: "",
            pageid:id
        };

        if (id > 0) { //存在值的情况
            $.http.json("suppliermenu/find", {   //查询
                Id: id
            }, {
                pass: function (data) {
                    data.pageid = id;
                    $("#form").templateRender({ el: "tp-form", data: data });//渲染模板，要先渲染才能获值
                    formValidInit();
                },
                error: function (d) {
                    console.log(d);
                }
            })
        } else {
            $("#form").templateRender({ el: "tp-form", data: inintData });//渲染模板，要先渲染才能获值
            formValidInit();
        }

        $("#form").on("click", "#btn-submit", function () { //保存按钮有添加和编辑
            if (!formValidEvent.check()) { return; }
            var apiUrl = "suppliermenu/insert";
            if (id > 0) {
                apiUrl = "suppliermenu/upd";
            }
            $("#form").ajaxFormSubmit(apiUrl, {
                pass: function (d) {
                    $.msgSucceed(d.Errmsg);
                    return
                },
                error: function (d) {
                    $.msgFall(d.Errmsg);
                }
            }, { addData: { Id: id, } })
            return
        });
    });
</script>
